{extend name="wap/default/base" /}
{block name="resources"}
<link rel="stylesheet" href="__TEMP__/{$style}/public/assets/css/amazeui.min.css">
<script type="text/javascript" src="__STATIC__/layer/laydate/laydate.js"></script>
<style type="text/css">
img{ width:100%; }
.head_back{position: absolute;top: 0;left: 10px;font-size:30px;color:#FFF;}
.am-header-danger{background-color: #F00;}
.layui-laydate, .layui-laydate-main{width:100%!important;}
.layui-laydate-content{margin:0 auto;text-align: center;}
.signinbtn{margin: 10px auto;}
/*td{background-color: #F00;}*/
.faicon{position: absolute;width:100%;z-index: 0;left:32%;right: 0;bottom:0;color: #d60338;}
.layui-laydate .layui-this {
  background-color: #fff!important;
  color: #666!important;
  border:1px solid #009688;
}
.layui-laydate .laydate-disabled{color: #666!important;}
.layui-laydate-content td, .layui-laydate-content th{width:2%;}
</style>
{/block}

{block name="main"}
<div class="am-g">
  <div id="signin" class="am-u-sm-12"></div>
  
  <div class="am-u-sm-12 signinbtn">
    {if $signstatus > 0}
    <span class="label-right am-btn am-btn-danger signbtn">签到</span>
    {else /}
    <span class="label-right am-btn am-btn-danger">已签到</span>
    {/if}
  </div>
  
</div>


<script>
laydate.render({
  elem: '#signin'
  ,btns: ['now']
  ,calendar: true
  ,position: 'static'
  ,min: '{:date("Y-m-d", mktime(0,0,0, date("m")-1, 1, date("Y")) )}'
  ,max: '{:date("Y-m-d")}'
  ,ready: function(date){
    console.log('date', date);
    distd();
    getsmiledate(date);

  }
  ,change: function(value, date, endDate){
    console.log('date', date);
    distd();
    getsmiledate(date);
  }
});

// 1、获取签到日期。 初始化当前年月，获取签到列表
// 2、根据日期添加标签。
var smiles  =  '<i class="fa fa-smile-o faicon" aria-hidden="true"></i>';
//禁止点击日历
function distd(){
  $('.layui-laydate-content tbody td').each(function(){
    if ( $(this).hasClass('laydate-disabled') == false ) {
      $(this).addClass('laydate-disabled');
    }
  });
}
// 获取签到日期，循环添加签到表情
function getsmiledate(cdate=''){
  $.post(
      "{:url('Signin/getSignlist')}",
      cdate,
      // { 'curyear': curyear , 'curmonth': curmonth, 'curdate':curdate, 'cdate':cdate },
      function(result){
        console.log(result);
        if (result.rescode < 0) {
          return ;
        }
        smileok(result);
      }
    );
  function smileok(qiandate){
    for (var i = qiandate.length - 1; i >= 0; i--) {
      $('td').each(function(){
        var ymd = $(this).attr('lay-ymd');
        // console.log(ymd);
        if ( ymd == qiandate[i] ) {
          $(this).append(smiles);
          return true;
        }
      });
    }
  }

}
// 处理是否签到过
function  getSign(){
  $('.signinbtn span').removeClass('signbtn');
  $('.signinbtn span').text('已签到');
  $('.signinbtn span').unbind('click');
}
// getSign();
$('.signbtn').on('click', function(){
  var curdate = new Date();
  var date  =  { 'year':curdate.getFullYear(), 'month':curdate.getMonth()+1 }
  $.post(
      "{:url('Signin/mebSignin')}",
      function(result){
        if ( result < 0 ) {
          // layer.msg('已签到！');
          // return ;
        }
        layer.msg('已签到！');
        getSign();
        getsmiledate(date);
      }
    );
});

</script>
{/block}
